import { http } from "@/utils/http"
import {
  OrderResult,
  PostMemberOrderData,
  PostMemberOrderResult,
  GetMemberOrderPreNowData,
  MemberOrderResult,
  PayWxPayMiniPayResult,
  getMemberOrderListParams,
  OrderListResult
} from '@/types/order'

/**
 * 获取预支付订单
 * @returns
 */
export const getMemberOrderPre = () =>
  http<OrderResult>({ url: '/member/order/pre' })

/**
* 提交订单
* @param data
* @returns
*/
export const postMemberOrder = (data: PostMemberOrderData) =>
  http<PostMemberOrderResult>({ url: '/member/order', method: 'POST', data })

/**
* 立即购买
* @param data
* @returns
*/
export const getMemberOrderPreNow = (data: GetMemberOrderPreNowData) =>
  http<OrderResult>({ url: '/member/order/pre/now', data })

/**
* 获取订单详情
* @param id
* @returns
*/
export const getMemberOrderById = (id: string) =>
  http<MemberOrderResult>({ url: `/member/order/${id}` })

/**
* 支付 - 微信 - 小程序
* @param orderId
* @returns
*/
export const getPayWxPayMiniPay = (orderId: string) =>
  http<PayWxPayMiniPayResult>({ url: '/pay/wxPay/miniPay', data: { orderId } })

export const payMentMock = (orderId: string) =>
  http({ url: '/pay/mock', data: { orderId } })


// 获取订单列表
export const getMemberOrderList = (data: getMemberOrderListParams) =>
  http<OrderListResult>({ url: '/member/order', data: { page: data.page, pageSize: data.pageSize, type: data.type } })

// 模拟发货
export const sendGoods = (id: string) => {
  http({ url: `/member/order/consignment/${id}` })
}

// 填写订单-获取再次购买订单
export const MemberOrderRepurchase = (id: string) =>
  http<OrderResult>({ url: `/member/order/repurchase/${id}` })

// 删除订单
export const MemberOrderDelete = (ids: string) =>
  http({ url: '/member/order', method: 'DELETE', data: ids })

// 确认收货
export const MemberOrderReceipt = (id: string) =>
  http({ url: `/member/order/${id}/receipt`, method: 'PUT' })